package com.zpark.config;

import com.zpark.interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: com.zpark.config
 * @ClassName: WebMvcConfig
 * @Description:
 * @author: RZS
 * @date: 2024/5/15  11:53
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 添加拦截器方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 定义拦截资源

        // 注册拦截器对象
        InterceptorRegistration interceptor = registry.addInterceptor(new UserInterceptor());

        // 添加拦截资源
        List<String> list = new ArrayList<>();
        list.add("/**");
        // ....

        interceptor.addPathPatterns(list);

        // 定义不拦截的资源
        List<String> lt = new ArrayList<>();
        lt.add("/user_login");
        interceptor.excludePathPatterns(lt);

    }
}
